<?php

namespace YmPhp\Admin\Http\Controllers;

use YmPhp\Admin\Models\Module;
use YmPhp\Admin\Form;
use YmPhp\Admin\Grid;
use YmPhp\Admin\Show;

class ModuleController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new Module(), function (Grid $grid) {
            $grid->column('id')->sortable();
            $grid->column('title');
            $grid->column('name');
            $grid->column('icon')->image('',60);
            $grid->column('is_commonly')->switch();
            $grid->column('is_wechat')->switch();
            $grid->column('is_tiktok')->switch();
            $grid->column('is_kwai')->switch();
            $grid->column('is_app')->switch();
            $grid->column('created_at');
            $grid->column('updated_at')->sortable();

            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');

            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new Module(), function (Show $show) {
            $show->field('id');
            $show->field('title');
            $show->field('name');
            $show->field('icon');
            $show->field('is_commonly');
            $show->field('is_wechat');
            $show->field('is_tiktok');
            $show->field('is_kwai');
            $show->field('is_app');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new Module(), function (Form $form) {
            $form->display('id');
            $form->text('title');
            $form->image('icon')->autoUpload()->move("module/" . date("Ym") . '/' .date("Ym"))->uniqueName()->saveFullUrl()->retainable();
            $form->switch('is_commonly');
            $form->switch('is_wechat');
            $form->switch('is_tiktok');
            $form->switch('is_kwai');
            $form->switch('is_app');
        });
    }
}
